package com.xiaoxin.service;

import cn.hutool.core.collection.CollUtil;
import com.xiaoxin.dubbo.api.AnnouncementApi;
import com.xiaoxin.model.domain.Announcement;
import com.xiaoxin.model.vo.AnnouncementVo;
import com.xiaoxin.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaoxiaode
 * @date 2021-09-10-17:13
 **/
@Service
public class AnnouncementService {

    @DubboReference(version = "1.0.0")
    private AnnouncementApi announcementApi;

    /*
    * 公告
    * */
    public PageResult announcements(Integer page, Integer pagesize) {
        // 查询所有公告
        List<Announcement> list=announcementApi.selectasd();
        if(CollUtil.isEmpty(list)){
            return new PageResult();
        }
        List<AnnouncementVo> vos=new ArrayList<>();
        for (Announcement announcement : list) {
            AnnouncementVo vo = AnnouncementVo.init(announcement);
            vos.add(vo);
        }
        // 构造返回
        return new PageResult(page,pagesize,0L, vos);
    }
}
